package com.oocl.chatroom.server;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Date;

import com.oocl.chatroom.network.protocol.Message;


public class Client1 {
    public static void main(String[] args) throws UnknownHostException, IOException, ClassNotFoundException, InterruptedException {
		Socket socket  = new Socket("127.0.0.1",8888);
		OutputStream out = socket.getOutputStream();
		ObjectOutputStream oout = new ObjectOutputStream(out);
		InputStream  in = socket.getInputStream();
		ObjectInputStream oin = new ObjectInputStream(in);
		Message msg1 = new Message("",2,"Client1","",(new Date()).getTime());
		oout.writeObject(msg1);
		while(true){
			Object obj = oin.readObject();
			Message msg = (Message)obj;
			if(msg.getReceiver().equals("*")){
				System.out.println(msg.getSender()+" say to all:  "+msg.getContent());
				
			}else{
				System.out.println(msg.getSender()+" say:  "+msg.getContent());
			}
		}
	}
}
